<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tcl_BooleanObj manual page - Tcl Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tcl C API</a> <small>&gt;</small> BoolObj</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<DL>
<DD><A HREF="BoolObj.htm#M2" NAME="L53">NAME</A>
<DL><DD>Tcl_NewBooleanObj, Tcl_SetBooleanObj, Tcl_GetBooleanFromObj &mdash; store/retrieve boolean value in a Tcl_Obj</DD></DL>
<DD><A HREF="BoolObj.htm#M3" NAME="L54">SYNOPSIS</A>
<DL>
<DD><B>#include &lt;tcl.h&gt;</B>
<DD>Tcl_Obj *
<DD><B>Tcl_NewBooleanObj</B>(<I>boolValue</I>)
<DD><B>Tcl_SetBooleanObj</B>(<I>objPtr, boolValue</I>)
<DD>int
<DD><B>Tcl_GetBooleanFromObj</B>(<I>interp, objPtr, boolPtr</I>)
</DL>
<DD><A HREF="BoolObj.htm#M4" NAME="L55">ARGUMENTS</A>
<DL class="arguments">
</DL>
<DD><A HREF="BoolObj.htm#M5" NAME="L56">DESCRIPTION</A>
<DD><A HREF="BoolObj.htm#M6" NAME="L57">SEE ALSO</A>
<DD><A HREF="BoolObj.htm#M7" NAME="L58">KEYWORDS</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
Tcl_NewBooleanObj, Tcl_SetBooleanObj, Tcl_GetBooleanFromObj &mdash; store/retrieve boolean value in a <A HREF="../TclLib/Object.htm">Tcl_Obj</A>
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tcl.h&gt;</B><BR>
<A HREF="../TclLib/Object.htm">Tcl_Obj</A> *<BR>
<B>Tcl_NewBooleanObj</B>(<I>boolValue</I>)<BR>
<B>Tcl_SetBooleanObj</B>(<I>objPtr, boolValue</I>)<BR>
int<BR>
<B>Tcl_GetBooleanFromObj</B>(<I>interp, objPtr, boolPtr</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT>int <B>boolValue</B> (in)<DD>
Integer value to be stored as a boolean value in a <A HREF="../TclLib/Object.htm">Tcl_Obj</A>.
<P><DT><A HREF="../TclLib/Object.htm">Tcl_Obj</A> <B>*objPtr</B> (in/out)<DD>
Points to the <A HREF="../TclLib/Object.htm">Tcl_Obj</A> in which to store, or from which to
retrieve a boolean value.
<P><DT><A HREF="../TclLib/Interp.htm">Tcl_Interp</A> <B>*interp</B> (in/out)<DD>
If a boolean value cannot be retrieved,
an error message is left in the interpreter's result value
unless <I>interp</I> is NULL.
<P><DT>int <B>*boolPtr</B> (out)<DD>
Points to place where <B>Tcl_GetBooleanFromObj</B>
stores the boolean value (0 or 1) obtained from <I>objPtr</I>.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
These procedures are used to pass boolean values to and from
Tcl as <A HREF="../TclLib/Object.htm">Tcl_Obj</A>'s.  When storing a boolean value into a <A HREF="../TclLib/Object.htm">Tcl_Obj</A>,
any non-zero integer value in <I>boolValue</I> is taken to be
the boolean value <B>1</B>, and the integer value <B>0</B> is
taken to be the boolean value <B>0</B>.
<P>
<B>Tcl_NewBooleanObj</B> creates a new <A HREF="../TclLib/Object.htm">Tcl_Obj</A>, stores the boolean
value <I>boolValue</I> in it, and returns a pointer to the new <A HREF="../TclLib/Object.htm">Tcl_Obj</A>.
The new <A HREF="../TclLib/Object.htm">Tcl_Obj</A> has reference count of zero.
<P>
<B>Tcl_SetBooleanObj</B> accepts <I>objPtr</I>, a pointer to
an existing <A HREF="../TclLib/Object.htm">Tcl_Obj</A>, and stores in the <A HREF="../TclLib/Object.htm">Tcl_Obj</A> <I>*objPtr</I>
the boolean value <I>boolValue</I>.  This is a write operation
on <I>*objPtr</I>, so <I>objPtr</I> must be unshared.  Attempts to
write to a shared <A HREF="../TclLib/Object.htm">Tcl_Obj</A> will panic.  A successful write
of <I>boolValue</I> into <I>*objPtr</I> implies the freeing of
any former value stored in <I>*objPtr</I>.
<P>
<B>Tcl_GetBooleanFromObj</B> attempts to retrieve a boolean value
from the value stored in <I>*objPtr</I>.
If <I>objPtr</I> holds a string value recognized by <B><A HREF="../TclLib/GetInt.htm">Tcl_GetBoolean</A></B>,
then the recognized boolean value is written at the address given
by <I>boolPtr</I>.
If <I>objPtr</I> holds any value recognized as
a number by Tcl, then if that value is zero a 0 is written at
the address given by <I>boolPtr</I> and if that
value is non-zero a 1 is written at the address given by <I>boolPtr</I>.
In all cases where a value is written at the address given
by <I>boolPtr</I>, <B>Tcl_GetBooleanFromObj</B> returns <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B>.
If the value of <I>objPtr</I> does not meet any of the conditions
above, then <B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B> is returned and an error message is
left in the interpreter's result unless <I>interp</I> is NULL.
<B>Tcl_GetBooleanFromObj</B> may also make changes to the internal
fields of <I>*objPtr</I> so that future calls to
<B>Tcl_GetBooleanFromObj</B> on the same <I>objPtr</I> can be
performed more efficiently.
<P>
Note that the routines <B>Tcl_GetBooleanFromObj</B> and
<B><A HREF="../TclLib/GetInt.htm">Tcl_GetBoolean</A></B> are not functional equivalents.
The set of values for which <B>Tcl_GetBooleanFromObj</B>
will return <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B> is strictly larger than
the set of values for which <B><A HREF="../TclLib/GetInt.htm">Tcl_GetBoolean</A></B> will do the same.
For example, the value
&ldquo;5&rdquo;
passed to <B>Tcl_GetBooleanFromObj</B>
will lead to a <B><A HREF="../TclCmd/catch.htm">TCL_OK</A></B> return (and the boolean value 1),
while the same value passed to <B><A HREF="../TclLib/GetInt.htm">Tcl_GetBoolean</A></B> will lead to
a <B><A HREF="../TclCmd/catch.htm">TCL_ERROR</A></B> return.

<H3><A NAME="M6">SEE ALSO</A></H3>
<B><A HREF="../TclLib/Object.htm">Tcl_NewObj</A></B>, <B><A HREF="../TclLib/Object.htm">Tcl_IsShared</A></B>, <B><A HREF="../TclLib/GetInt.htm">Tcl_GetBoolean</A></B>
<H3><A NAME="M7">KEYWORDS</A></H3>
<A href="../Keywords/B.htm#boolean">boolean</A>, <A href="../Keywords/V.htm#value">value</A>
<div class="copy">Copyright &copy; 1996-1997 Sun Microsystems, Inc.
</div>
</BODY></HTML>
